package com.lottery.api.controller.activity;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lottery.api.annotation.CheckLoginAop;
import com.lottery.api.annotation.CoerceLoginAop;
import com.lottery.api.service.ActivityInfoService;
import com.lottery.common.contants.ReQueryResult;
import com.lottery.common.entity.*;
import com.lottery.common.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.nutz.lang.util.NutMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;

import static com.lottery.common.contants.Constants.*;


/**
 * @author furutaka
 */
@RestController
@RequestMapping("/activity")
@Slf4j
@Api(value = "/activity",tags="获取活动图片")
public class ActivityInfoController {
	private ReQueryResult result;

	@Autowired
	private ActivityInfoService activityInfoService;

	@Autowired
	private TextInfoService textInfoService;
	@Autowired
	private NewsFlashInfoService newsFlashInfoService;
	@Autowired
	private ShortReportInfoService shortReportInfoService;
	@Autowired
	private CommentInfoService commentInfoService;
	@Autowired
	private CommentSubInfoService commentSubInfoService;
	/**
	 * 获取所有活动图片
	 * @return
	 */
	@ApiOperation(value = "获取所有活动图片")
	@RequestMapping(value = "", method = RequestMethod.GET)
	public ReQueryResult<ActivityInfo> articles(){
		result = new ReQueryResult();
		ActivityInfo param=new ActivityInfo();
		QueryWrapper<ActivityInfo> queryWrapper = new QueryWrapper<>(param);
		queryWrapper.eq("status",TYPE_ONE).eq("is_del",TYPE_ONE);
		List<ActivityInfo> list=activityInfoService.list(queryWrapper);
		result.setData(list);
		result.success(SUCCESS_DESC);
		return result;
	}

	/**
	 *按类型获得活动图片
	 * @param type
	 * @return
	 */
	@ApiOperation(value = "按类型获得活动图片")
	@ApiImplicitParam(name = "type",value = "活动类型 1.app轮播图 2.pc轮播图 3.广告图 4.公告 5.资讯 6.热搜词",dataType="Integer")
	@RequestMapping(value = "/{type}", method = RequestMethod.GET)
	public ReQueryResult<ActivityInfo> articles(@PathVariable Integer type){
		result = new ReQueryResult();
		ActivityInfo param=new ActivityInfo();
		param.setDetailType(type);
		QueryWrapper<ActivityInfo> queryWrapper = new QueryWrapper<>(param);
		queryWrapper.eq("status",TYPE_ONE).eq("is_del",TYPE_ONE);
		List<ActivityInfo> list=activityInfoService.list(queryWrapper);
		result.setData(list);
		result.success(SUCCESS_DESC);
		return result;
	}


	@ApiOperation(value = "按类型获得富文本内容")
	@ApiImplicitParam(name = "type",value = "文本类型 0402 功能介绍 0403 法律声明",dataType="String")
	@RequestMapping(value = "/text/{type}", method = RequestMethod.GET)
	public ReQueryResult<TextInfo> textInfo(@PathVariable String type){
		result = new ReQueryResult();
		TextInfo param=new TextInfo();
		param.setType(type);
		QueryWrapper<TextInfo> queryWrapper = new QueryWrapper<>(param);
		TextInfo list=textInfoService.getOne(queryWrapper);
		result.setData(list);
		result.success(SUCCESS_DESC);
		return result;
	}

	//二期新增
//
//	@ApiOperation(value = "资讯列表")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "index",value = "页码 ",dataType="Integer"),
//			@ApiImplicitParam(name = "length",value = "长度",dataType="Integer")
//	})
//	@RequestMapping(value = "/newsFlash", method = RequestMethod.GET)
//	public ReQueryResult<NewsFlashInfo> newsFlash(Integer index,Integer length){
//		result = new ReQueryResult();
//		QueryWrapper<NewsFlashInfo> queryWrapper = new QueryWrapper<>();
//		queryWrapper.orderByDesc("id");
//		Page<NewsFlashInfo> page = new Page<>(index,length);
//		IPage<NewsFlashInfo> list=newsFlashInfoService.page(page,queryWrapper);
//		result.setData(list);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//
//	@ApiOperation(value = "资讯详情")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "id",value = " ",dataType="Integer"),
//	})
//	@RequestMapping(value = "/newsFlash/{id}", method = RequestMethod.GET)
//	public ReQueryResult<NewsFlashInfo> newsFlashDetail(  @PathVariable Long id){
//		result = new ReQueryResult();
//		NewsFlashInfo info=newsFlashInfoService.getById(id);
//
//		info.setClickNum(info.getClickNum()+1);
//		newsFlashInfoService.updateById(info);
//		result.setData(info);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//
//
//	@ApiOperation(value = "短报列表")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "isList",value = "是否公共列表 0 是 1个人 ",dataType="Integer"),
//			@ApiImplicitParam(name = "index",value = "页码 ",dataType="Integer"),
//			@ApiImplicitParam(name = "length",value = "长度",dataType="Integer"),
//	})
//	@RequestMapping(value = "/shortReport", method = RequestMethod.GET)
//	@CheckLoginAop
//	public ReQueryResult<IPage<ShortReportInfo>> shortReportList(HttpServletRequest request, @ApiIgnore() MemberInfo memberInfo,
//																Integer isList, Integer index, Integer length){
//		result = new ReQueryResult();
//		QueryWrapper<ShortReportInfo> queryWrapper = new QueryWrapper<>();
//		if (isList==TYPE_ONE){
//			queryWrapper.eq("member_id",memberInfo.getId());
//		}
//		queryWrapper.orderByDesc("is_top","id");
//		Page<ShortReportInfo> page = new Page<>(index,length);
//		IPage<ShortReportInfo> list=shortReportInfoService.page(page,queryWrapper);
//		result.setData(list);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//	@ApiOperation(value = "发布短报")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "title",value = "标题 ",dataType="String"),
//			@ApiImplicitParam(name = "content",value = "内容",dataType="String"),
//			@ApiImplicitParam(name = "memberId",value = " ",dataType="String"),
//			@ApiImplicitParam(name = "image",value = "图片",dataType="String"),
//	})
//	@RequestMapping(value = "/shortReport", method = RequestMethod.POST)
//	@CoerceLoginAop
//	public ReQueryResult shortReport(HttpServletRequest request, @ApiIgnore() MemberInfo memberInfo,ShortReportInfo info){
//		result = new ReQueryResult();
//		shortReportInfoService.save(info);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//
//	@ApiOperation(value = "短报详情")
//	@ApiImplicitParam(name = "index",value = "页码 ",dataType="Integer")
//	@RequestMapping(value = "/shortReport/{id}", method = RequestMethod.GET)
//	@CheckLoginAop
//	public ReQueryResult<ShortReportInfo> shortReportDetail(@PathVariable Long id){
//		result = new ReQueryResult();
//		QueryWrapper<ShortReportInfo>queryWrapper=new QueryWrapper<>();
//		queryWrapper.select("*");
//		queryWrapper.eq("id",id);
//		ShortReportInfo info=shortReportInfoService.getOne(queryWrapper);
//		result.setData(info);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//
//
//	@ApiOperation(value = "短报 点赞")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "id",value = " ",dataType="Integer"),
//	})
//	@RequestMapping(value = "/shortReport/{id}", method = RequestMethod.POST)
//	public ReQueryResult shortReportUpdate(@PathVariable Long id){
//		result = new ReQueryResult();
//		UpdateWrapper<ShortReportInfo> updateWrapper = new UpdateWrapper<>();
//		updateWrapper.eq("id",id).setSql("like_num = like_num+1");
//		shortReportInfoService.update(updateWrapper);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//
//	@ApiOperation(value = "短报取消点赞")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "id",value = " ",dataType="Integer"),
//	})
//	@RequestMapping(value = "/shortReport/{id}", method = RequestMethod.PUT)
//	public ReQueryResult shortReportDel(  @PathVariable Long id){
//		result = new ReQueryResult();
//		UpdateWrapper<ShortReportInfo> updateWrapper = new UpdateWrapper<>();
//		updateWrapper.eq("id",id).setSql("like_num = like_num-1").ne("like_num",TYPE_ZERO);
//		shortReportInfoService.update(updateWrapper);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//
//	@ApiOperation(value = "评论列表")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "type",value = "0801 短报 0802资讯 ",dataType="Integer"),
//			@ApiImplicitParam(name = "index",value = "页码 ",dataType="Integer"),
//			@ApiImplicitParam(name = "length",value = "长度",dataType="Integer"),
//	})
//	@RequestMapping(value = "/comment", method = RequestMethod.GET)
//	public ReQueryResult<CommentInfo> commentList(Integer type,Integer index, Integer length){
//		result = new ReQueryResult();
//		NutMap nutMap=new NutMap();
//		nutMap.setv("type",type);
//		nutMap.setv("startNum",nutMap.getInt("pageLength")*(nutMap.getInt("pageIndex")-1))
//				.setv("endNum",nutMap.getInt("pageLength"));
//		List<CommentInfo>list = commentInfoService.selectCommentByType(nutMap);
//		result.setData(list);
//		result.success(SUCCESS_DESC);
//		return result;
//	}
//
//
//	@ApiOperation(value = "发表评论")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "type",value = "1 发表评论 2回复",dataType="Integer"),
//			@ApiImplicitParam(name = "relationType",value = " 关联类型 0801短报 0802资讯",dataType="Integer"),
//			@ApiImplicitParam(name = "relationId",value = " 关联id ",dataType="Integer"),
//			@ApiImplicitParam(name = "comment",value = "评论内容",dataType="Integer"),
//			@ApiImplicitParam(name = "topComment",value = "回复id",dataType="Integer"),
//			@ApiImplicitParam(name = "extraReplyId",value = "额外回复人id",dataType="Integer"),
//			@ApiImplicitParam(name = "extraReplyName",value = "额外回复人昵称",dataType="Integer"),
//	})
//	@RequestMapping(value = "/comment", method = RequestMethod.POST)
//	@CoerceLoginAop
//	public ReQueryResult  comment(HttpServletRequest request, @ApiIgnore() MemberInfo memberInfo,
//											  Integer type,String relationType,Long relationId,String comment,
//											  Long topComment,Long extraReplyId,String extraReplyName){
//		result = new ReQueryResult();
//		boolean flag=false;
//		boolean flag2=false;
//
//		if (type==TYPE_ONE){
//			flag=commentInfoService.save(new CommentInfo(relationType,relationId,comment,memberInfo.getId(),memberInfo.getNickName()));
//		}
//		if (type==TYPE_TWO){
//			flag=commentSubInfoService.save(new CommentSubInfo(topComment,memberInfo.getId(),memberInfo.getNickName(),comment,extraReplyId,extraReplyName));
//		}
//		if (!flag){
//			result.error(INSIDE_WRONG_DESC);
//			return result;
//		}
//		if ("0801".equals(relationType)){
//			UpdateWrapper<ShortReportInfo> updateWrapper = new UpdateWrapper<>();
//			updateWrapper.eq("id",relationId).setSql("like_num = like_num+1");
//			shortReportInfoService.update(updateWrapper);
//		}
//		if ("0802".equals(relationType)){
//			UpdateWrapper<NewsFlashInfo> updateWrapper = new UpdateWrapper<>();
//			updateWrapper.eq("id",relationId).setSql("click_num = click_num+1");
//			newsFlashInfoService.update(updateWrapper);
//		}
//
//		result.success(SUCCESS_DESC);
//		return result;
//	}


}
